package com.itheima.controller;

import com.itheima.domain.SmsFlashPromotionProductRelation;
import com.itheima.manager.SmsProductRelationManager;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ChenTianSui
 * @date 2022/11/12 23:37
 */
@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashProductRelationController {
    @Autowired
    private SmsProductRelationManager smsProductRelationManager;

    @GetMapping("/list")
    public R<PageBeanVo> findListByPage(Integer flashPromotionId, Integer flashPromotionSessionId,
                                        @RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                        @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        return smsProductRelationManager.findListByPage(flashPromotionId, flashPromotionSessionId, pageNum, pageSize);

    }

    @PostMapping("/create")
    public R create(@RequestBody List<SmsFlashPromotionProductRelation> relationList) {
        return smsProductRelationManager.create(relationList);

    }

    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        return smsProductRelationManager.delete(id);

    }

    @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id, @RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelation) {
        return smsProductRelationManager.update(id, smsFlashPromotionProductRelation);

    }

    /**
     * 获取管理商品促销信息
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SmsFlashPromotionProductRelation> findById(@PathVariable Integer id) {
        return smsProductRelationManager.findById(id);

    }


}
 
